package com.ssmTest.controller;

import com.ssmTest.dao.IOrderDao;
import com.ssmTest.model.MachineUserInformation;
import com.ssmTest.model.Order;
import com.ssmTest.model.UserInformation;
import com.ssmTest.service.IMachineUserInformationService;
import com.ssmTest.service.IOrderService;
import com.ssmTest.service.IUserInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class OrderController {
    @Resource
    private IOrderDao iOrderDao;
    @Autowired
    private IOrderService iOrderService;

    @Autowired
    private IUserInformationService iUserInformationService;
    @Autowired
    private IMachineUserInformationService iMachineUserInformationService;

    //订单列表界面
    @RequestMapping(value = "/orderList.do")
    public String orderList(ModelMap modelMap) {
        List<Order> list = iOrderService.orderList();
        modelMap.addAttribute("list", list);
        return "orderList";
    }

    @RequestMapping(value = "/getInformationByOrder.do")
    public String getInformationByOrder(int id, ModelMap modelMap) {
        Order order = iOrderService.selectOrderByID(id);
        if (order.getType() == 1) {
            UserInformation userInformation = iUserInformationService.selectUserInformation(id);
            modelMap.addAttribute("userinformation", userInformation);
            modelMap.addAttribute("type", 1);
        } else if (order.getType() == 2) {
            MachineUserInformation machineUserInformation = iMachineUserInformationService.selectMachineUserInformation(id);
            modelMap.addAttribute("machineinformation", machineUserInformation);
            modelMap.addAttribute("type", 2);
        }
        return "information_details";
    }
}
